<?php
namespace bdd;

class Connection {

	protected $_link;

    public final static function getConnection() {
		$classe = get_called_class();
        static $conn = null;
        if ($conn == null)
            $conn = new $classe();
        return $conn;
    }	
	
	private final function __construct()
	{
		$pass = null;
		$param = \api\arrayFromIni('parametres', __NAMESPACE__);
	
		if(isset($param[APIMODE]['password'])) {
			$dsn = $param[APIMODE]['sgbd'] . '://' . $param[APIMODE]['user'] . ':' . $param[APIMODE]['password'] . '@' . $param[APIMODE]['host'] . '/' . $param[APIMODE]['base'];
			
		} else {
			$dsn = $param[APIMODE]['sgbd'] . '://' . $param[APIMODE]['user'] . '@' . $param[APIMODE]['host'] . '/' . $param[APIMODE]['base'];
		}
				
		//\api\debug\Printer::prints($dsn);
		
		$manager = \Doctrine_Manager::getInstance();
		
		try {
			$this->_link = \Doctrine_Manager::connection($dsn);
		} catch (\Exception $e) {
			throw new \Exception('Connexion échouée: ' . $e->getMessage());
		}

	}
	
	public final function getLink() {
		return $this->_link;
	}
	
	protected final function execPreparedQuery($query) {
		$stmt = $this->_link->prepare($query);
		$stmt->execute();
		return $stmt;
	}

	
	
}

?>